﻿using System;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Description;
using Dqaqs.Host.RestSvc;
using log4net;

namespace Dqaqs.Host
{
	internal class DqaqsHost
	{
		private readonly ILog _log = LogManager.GetLogger(typeof (DqaqsHost));
		private ServiceHost _host;

		public DqaqsHost()
		{
		}

		public void Start()
		{
			Console.WriteLine("Hosting the service.");
			_log.Info("Starting service");
		    var baseUri = ConfigurationManager.AppSettings["host"];
			_host = new ServiceHost(typeof (MethodRunService));
			var se = _host.AddServiceEndpoint(typeof (IMethodRunService),
			                                  new WebHttpBinding(), baseUri);
			se.Behaviors.Add(new WebHttpBehavior());
			_host.Open();
		}

		public void Stop()
		{
			Console.WriteLine("Stopped the shit.");
			_host.Close();
		}
	}
}
